using UnityEngine;
using TMPro;

public class CountDown : MonoBehaviour
{
    public float playTime = 180;
    public float timer;
    public TextMeshProUGUI displayText;
    bool isGameStart;

    private void Start()
    {
        timer = playTime;
    }

    private void Update()
    {
        if (GameManager.Instance.IsGameOver) return;
        
        if(isGameStart)
        {
            timer -= Time.deltaTime;
            displayText.text = TimeUtils.ToReadableTime(timer);
            if(timer <= 0)
            {
                timer = 0;
                isGameStart = false;
                GameManager.Instance.TimeOver();
            }
        }
    }

    public void GameStart()
    {
        isGameStart = true;
    }
}
